type MouseEvent = {
  eventType: "click";
  x: number;
  y: number;
};

type KeyEvent = {
  eventType: "keyUp";
  key: number;
};

// 获取相同的属性名，相同的属性名的属性值会变为联合类型
type Keys = keyof (MouseEvent | KeyEvent);

type EventRec = EventFunctions<MouseEvent | KeyEvent, "eventType">;

type EventFunctions<
  Events extends Record<string, any>,
  EventKey extends keyof Events
> = {
  // in 后面只能接 string / number /symbol 的联合类型
  // [Event in Events as Event extends Events ? Event[EventKey] : never]
  [Event in Events as Event[EventKey]]: (event: Event) => any;
};

export {};
